<template>
  <div class="btnComponent">
    <!--  刷新  -->
    <el-button v-if="btnArr.includes('reload')" size="mini" @click="common('refresh')">{{ $t('btn.reload') }}</el-button>
    <!--  新增  -->
    <el-button v-if="btnArr.includes('newy')" type="primary" size="mini" @click.native="common('newly')">
      {{ $t('btn.add') }}
    </el-button>
    <el-button v-if="btnArr.includes('filter')" type="primary" size="mini" @click="common('filter')">{{ $t('market.filter') }}</el-button>
    <!--  保存  -->
    <el-button v-if="btnArr.includes('save')" :disabled="disabArr.includes('save')" type="primary" size="mini" @click="common('save')">
      {{ $t('btn.save') }}
    </el-button>
    <!--  提交 撤销  -->
    <el-dropdown v-if="btnArr.includes('sub')" class="marL">
      <el-button type="success" size="mini" @click.native="common('submit')">
        {{ $t('btn.sub') }}<i class="el-icon-arrow-down el-icon--right" />
      </el-button>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item @click.native="common('submit')">{{ $t('btn.sub') }}</el-dropdown-item>
        <el-dropdown-item :disabled="disabArr.includes('nosub')" @click.native="common('noSubmit')">{{ $t('btn.noSub') }}</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <!--  审核 反审核  -->
    <el-dropdown v-if="btnArr.includes('pass')" class="marL">
      <el-button type="warning" size="mini" @click.native="common('audit')">
        {{ $t('btn.audit') }}<i class="el-icon-arrow-down el-icon--right" />
      </el-button>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item @click.native="common('audit')">{{ $t('btn.audit') }}</el-dropdown-item>
        <el-dropdown-item @click.native="common('noAudit')">{{ $t('btn.noAudit') }}</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <!-- 不同意   -->
    <el-button v-if="btnArr.includes('disagree')" class="marL" size="mini" type="primary" @click="common('disagree')">{{ $t('market.consentNo') }}</el-button>
    <!-- 转发   -->
    <el-button v-if="btnArr.includes('ward')" class="marL" size="mini" type="primary" @click="common('forward')">{{ $t('market.forward') }}</el-button>
    <!--  删除  -->
    <el-button v-if="btnArr.includes('remove')" class="marL" size="mini" type="danger" @click="common('del')">{{ $t('btn.del') }}</el-button>
    <!--  复制  -->
    <el-button v-if="btnArr.includes('copy')" class="marL" size="mini" type="primary" @click.native="common('copyDa')">{{ $t('btn.copy') }}</el-button>
    <!--  下推  -->
    <el-button v-if="btnArr.includes('push')" class="marL" size="mini" type="primary" @click="common('pushDown')">{{ $t('btn.push') }}</el-button>
    <!--  现金流量  -->
    <el-button v-if="btnArr.includes('cashFlow')" class="marL" size="mini" type="primary" @click="common('cashFlow')">{{ $t('menu.cashFlow') }}</el-button>
    <!--  推送  -->
    <el-button v-if="btnArr.includes('pushOrder')" class="marL" size="mini" type="primary" @click="common('pushOrder')">推送</el-button>
    <!--  选项  -->
    <el-dropdown v-if="btnArr.includes('option')" class="marL">
      <el-button type="primary" size="mini">{{ $t('btn.option') }}<i class="el-icon-arrow-down el-icon--right" /></el-button>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item :disabled="disabArr.includes('toExcel')" @click.native="common('toExcel')">
          {{ $t('btn.toExcel') }}</el-dropdown-item>
        <el-dropdown-item :disabled="disabArr.includes('com1')" @click.native="common('handleCom1')">
          {{ $t('btn.com1') }}</el-dropdown-item>
        <el-dropdown-item :disabled="disabArr.includes('com2')" @click.native="common('handleCom2')">
          {{ $t('btn.com2') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('com3')" @click.native="common('handleCom3')">
          装箱单(套打)</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('hangPass')" @click.native="common('hangAudit')">
          {{ $t('btn.hangAduit') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('hangPass')" @click.native="common('hangAudit2')">
          {{ $t('btn.hangNoAduit') }}</el-dropdown-item>
        <el-dropdown-item v-if="!disabArr.includes('using')" @click.native="common('startUsing')">
          {{ $t('btn.dis') }}</el-dropdown-item>
        <el-dropdown-item v-if="!disabArr.includes('using')" @click.native="common('forbidden')">
          {{ $t('btn.disab') }}</el-dropdown-item>
        <el-dropdown-item v-if="!disabArr.includes('close')" @click.native="common('startUsing')">
          {{ $t('btn.clos') }}</el-dropdown-item>
        <el-dropdown-item v-if="!disabArr.includes('close')" @click.native="common('forbidden')">
          {{ $t('btn.closed') }}</el-dropdown-item>
        <el-dropdown-item v-if="!disabArr.includes('cancel')" @click.native="common('NoCalncellation')">
          {{ $t('btn.cencell') }}</el-dropdown-item>
        <el-dropdown-item v-if="!disabArr.includes('cancel')" @click.native="common('cancellation')">
          {{ $t('btn.cencellation') }}</el-dropdown-item>
        <el-dropdown-item v-if="!disabArr.includes('freeze')" @click.native="common('refreezing')">
          {{ $t('btn.refreezing') }}</el-dropdown-item>
        <el-dropdown-item v-if="!disabArr.includes('freeze')" @click.native="common('freeze')">
          {{ $t('btn.freeze') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('termin')" @click.native="common('termin')">
          {{ $t('btn.termin') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('termin')" @click.native="common('termin1')">
          {{ $t('btn.termin1') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('terentry')" @click.native="common('terentry')">
          {{ $t('btn.terentry') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('terentry')" @click.native="common('terentry1')">
          {{ $t('btn.terentry1') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('closure')" @click.native="common('closure')">
          {{ $t('btn.settle') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('closure')" @click.native="common('closure1')">
          {{ $t('btn.settle1') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('closeHang')" @click.native="common('closeHang')">
          {{ $t('btn.settleHang') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('closeHang')" @click.native="common('closeHang1')">
          {{ $t('btn.settleHang1') }}</el-dropdown-item>
        <el-dropdown-item :disabled="disabArr.includes('chart')" @click.native="flowChart">
          {{ $t('btn.chart') }}</el-dropdown-item>
        <el-dropdown-item v-if="disabArr.includes('sort')" @click.native="common('sort')">
          {{ $t('btn.sort') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('batchFill')" @click.native="isbillDialog=true">
          {{ $t('btn.batchFill') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('allocation')" @click.native="common('allot')">
          {{ $t('btn.allocation') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('hangUp')" @click.native="common('hangUp')">
          {{ $t('btn.hangUp') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('hangUp')" @click.native="common('hangUp1')">
          {{ $t('btn.hangUp1') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('hangUp1')" @click.native="common('hangUp2')">
          {{ $t('btn.entryHangUp') }}</el-dropdown-item>
        <el-dropdown-item v-if="btnArr.includes('hangUp1')" @click.native="common('hangUp3')">
          {{ $t('btn.entryHangUp1') }}</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <!--凭证-->
    <el-dropdown v-if="btnArr.includes('voucher')" class="marL">
      <el-button type="primary" size="mini">
        {{ $t('market.voucherType') }}<i class="el-icon-arrow-down el-icon--right" />
      </el-button>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item @click.native="common('voucher')">{{ $t('menu.credentialsTask') }}</el-dropdown-item>
        <el-dropdown-item :disabled="disabArr.includes('voucherLok')" @click.native="common('voucherLok')">{{ $t('market.voucherLook') }}</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <el-button v-if="btnArr.includes('check')" class="marL" size="mini" type="primary" @click="common('check')">
      {{ $t('btn.up') }}
    </el-button>
    <el-button v-if="btnArr.includes('check')" class="marL" size="mini" type="primary" @click="common('check1')">
      {{ $t('btn.down1') }}
    </el-button>
    <el-button v-if="btnArr.includes('list')" class="marL" size="mini" type="primary" @click="pushView">
      {{ $t('btn.list') }}
    </el-button>
    <el-dropdown v-if="btnArr.includes('config')" class="marL">
      <!--   业务操作   -->
      <el-button type="primary" size="mini">{{ $t('btn.config') }}<i class="el-icon-arrow-down el-icon--right" /></el-button>
      <el-dropdown-menu slot="dropdown">
        <!--   配置   -->
        <el-dropdown-item @click.native="configuration">{{ $t('btn.deploy') }}</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <el-button v-if="btnArr.includes('settle')" class="marL" size="mini" type="success" @click="common('settle')">
      {{ $t('btn.settle') }}
    </el-button>
    <el-button v-if="btnArr.includes('matLi')" class="marL" size="mini" type="success" @click="common('matLi')">
      {{ $t('btn.materialsList') }}<!--用料清单查询-->
    </el-button>
    <!--  业务操作-配置 弹窗  -->
    <el-dialog
      :title="$t('btn.deploy')"
      model
      :visible.sync="isconfigDialog"
      :close-on-click-modal="false"
      width="600px"
      center
    >
      <div style="min-height: 100px;">
        <el-checkbox-group v-model="configDe">
          <el-checkbox v-for="item in allocation" :key="item" :label="item.fid">
            {{ item.fname }}
          </el-checkbox>
        </el-checkbox-group>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isconfigDialog = false">{{ $t('btn.cancel') }}</el-button>
        <el-button size="mini" type="primary" @click="configSuccess()">
          {{ $t('btn.confirm') }}
        </el-button>
      </span>
    </el-dialog>
    <!--  是否批量填充  -->
    <el-dialog
      :title="$t('btn.deploy')"
      model
      :visible.sync="isbillDialog"
      :close-on-click-modal="false"
      width="600px"
      center
    >
      <div>
        <el-checkbox v-model="checked">{{ $t('market.batchFill') }}</el-checkbox>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isbillDialog = false">{{ $t('btn.cancel') }}</el-button>
        <el-button size="mini" type="primary" @click="fillSuccess()">
          {{ $t('btn.confirm') }}
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { queryCommon, updateCommon, updateIsFill } from '@/api/purchaseManagement/purchaseOrder'

export default {
  props: {
    btnArr: { // 显示按钮
      type: Array,
      default: function() {
        return []
      }
    },
    disabArr: { // 禁止使用按钮
      type: Array,
      default: function() {
        return []
      }
    },
    fbillno: { // 全流程图数据
      type: String,
      default: ''
    },
    config: { // 配置
      type: String,
      default: ''
    },
    list: { // 列表路由
      type: String,
      default: ''
    },
    url: { // 列表URL-列表是否填充
      type: String,
      default: ''
    }
  },
  data() {
    return {
      isconfigDialog: false,
      isbillDialog: false,
      allocation: [],
      configDe: [],
      checked: false // 是否批量填充
    }
  },
  methods: {
    common(ev) {
      this.$emit(ev)
    },
    // 套打
    handleCom(ev) {
      this.$emit('handleCom', ev)
    },
    // 全流程图
    flowChart() {
      if (!this.fbillno) {
        this.$message.warning('请选择数据')
        return
      }
      this.$router.push({ path: `/flowChart/${this.fbillno}` })
    },
    // 跳转列表
    pushView() {
      this.$router.push({ path: this.list })
    },
    // 配置弹窗
    configuration() {
      this.isconfigDialog = true
      this.gration()
    },
    // 配置项
    gration() {
      queryCommon({ fnumber: this.config }).then(res => {
        this.allocation = res.data
        this.configDe = []
        this.allocation.forEach(res => {
          res.fvalue === '1' && this.configDe.push(res.fid)
        })
      })
    },
    // 配置确认
    configSuccess() {
      this.allocation.forEach(item => {
        if (this.configDe.length) {
          this.configDe.forEach(ite => {
            if (item.fid === ite) {
              item.fvalue = '1'
            }
          })
        } else {
          item.fvalue = '0'
        }
      })
      const DATA = this.allocation
      updateCommon(DATA).then(res => {
        if (res.code === 0) {
          this.configDe = []
          this.isconfigDialog = false
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            type: 'error'
          })
        }
      })
    },
    // 是否批量填充
    fillSuccess() {
      const DATA = {
        url: this.url,
        isFill: this.checked ? 1 : 0
      }
      updateIsFill(DATA).then(res => {
        if (res.code === 0) {
          this.$emit('refresh')
          this.isbillDialog = false
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            type: 'error'
          })
        }
      })
    }
  }
}
</script>

<style scope lang="scss">
.btnComponent {
  .marL {
    margin-left: 10px;
    cursor: default;
  }
}
</style>
